﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Black_Jack
{
    public class analyz : Card
    {
        public int q = 0, po1=0, po2=0, po3=0, pt1=0, pt2=0, pt3=0;
        
        public int[] player1 = new int[7];
        public int[] player2 = new int[7];

        public void kombo1()
        {
            int p = 0, s = 0, z = 1, w = 0, b = 0;
            int t = 0, a=0;
            for (int i = 0; i < 7; i++)
            {
                player1[i] = razd[i];
            }
            while (p < 7)
            {
                while (z < 7)
                {
                    if (player1[p] > player1[z])
                    {
                        s = player1[z];
                        player1[z] = player1[p];
                        player1[p] = s;   
                    }
                    z++;
                }
                p++;
                z = p + 1;
                
            }

           // player1 = new int[] { 1, 10, 13, 17, 18, 19, 26 };
            //player1 = new int[] { 1, 10, 13, 17, 22, 23, 26 };
            //player1 = new int[] { 1, 7, 11, 17, 22, 24, 32 };
            
            w = royal();
            if (w > 99)
            {
                a = w % 100;
                w = 8;
            }
            else
            {
                w = kare();
                if (w > 0)
                {
                    a = w / 10;
                    b = w%10;
                    w = 7;
                }
                else
                {
                    w = ful();
                    if (w > 99)
                    {
                        a = (w-100)/10;
                        b = (w -100)%10;
                        w = 6;
                    }
                    else
                    {
                        t = flush();
                        if (t > 0)
                        {
                            a = t;
                            w = 5;
                        }
                        else
                        {
                            w = stret();
                            if (w > 0)
                            {
                                a = w;
                                w = 4;
                            }
                            else
                            {
                                w = tri();
                                if (w > 10)
                                {
                                    a = w;
                                    w = 3;
                                }
                                else
                                {
                                    w = papa();
                                    if (w > 100)
                                    {
                                        a = w;
                                        w = 2;
                                    }
                                    else
                                    {
                                        w = para();
                                        if (w > 1000)
                                        {
                                            a = w;
                                            w = 1;
                                        }
                                        else
                                        {
                                            w = kiker();
                                            if (w > 1000)
                                            {
                                                a = w;
                                                w = 0;
                                            }
                                        }
                                    }
 
                                }

                            }
 
                        }
 
                    }
                }
            }
            po1 = w;
            po2 = a;
            po3 = b;
            
        }

        public void kombo2()
        {
            int p = 0, s = 0, z = 1, w = 0, b = 0;
            int t = 0, a = 0;
            for (int i = 0; i < 7; i++)
            {
                player1[i] = razd[i+2];
            }
            while (p < 7)
            {
                while (z < 7)
                {
                    if (player1[p] > player1[z])
                    {
                        s = player1[z];
                        player1[z] = player1[p];
                        player1[p] = s;
                    }
                    z++;
                }
                p++;
                z = p + 1;

            }

            // player1 = new int[] { 1, 10, 13, 17, 18, 19, 26 };
            //player1 = new int[] { 1, 10, 13, 17, 22, 23, 26 };
            //player1 = new int[] { 1, 7, 11, 17, 22, 24, 32 };

            w = royal();
            if (w > 99)
            {
                a = w % 100;
                w = 8;
            }
            else
            {
                w = kare();
                if (w > 0)
                {
                    a = w / 10;
                    b = w % 10;
                    w = 7;
                }
                else
                {
                    w = ful();
                    if (w > 99)
                    {
                        a = (w - 100) / 10;
                        b = (w - 100) % 10;
                        w = 6;
                    }
                    else
                    {
                        t = flush();
                        if (t > 0)
                        {
                            a = t;
                            w = 5;
                        }
                        else
                        {
                            w = stret();
                            if (w > 0)
                            {
                                a = w;
                                w = 4;
                            }
                            else
                            {
                                w = tri();
                                if (w > 10)
                                {
                                    a = w;
                                    w = 3;
                                }
                                else
                                {
                                    w = papa();
                                    if (w > 100)
                                    {
                                        a = w;
                                        w = 2;
                                    }
                                    else
                                    {
                                        w = para();
                                        if (w > 1000)
                                        {
                                            a = w;
                                            w = 1;
                                        }
                                        else
                                        {
                                            w = kiker();
                                            if (w > 1000)
                                            {
                                                a = w;
                                                w = 0;
                                            }
                                        }
                                    }

                                }

                            }

                        }

                    }
                }
            }
            pt1 = w;
            pt2 = a;
            pt3 = b;

        }

        public int rez()
        {
            int p = 0;
            if (po1 > pt1)
            {
                p = 1;
            }
            else if (pt1 > po1)
            {
                p = 2;
            }
            else if (po2 > pt2)
            {
                p = 1;
            }
            else if (pt2 > po2)
            {
                p = 2;
            }
            else if (po3 > pt3)
            {
                p = 1;
            }
            else if (pt3 > po3)
            {
                p = 2;
            }
            else p = 0;

            return (p);
        }
        public int royal()
        {
            int p = 0, i = 0, f=0;
            for (i = 0; i < 3; i++)
            {
             p=player1[i];
             if ((player1[1] == p + 4) || (player1[2] == p + 4) || (player1[3] == p + 4))
                    {
                        if ((player1[2] == p + 8)||(player1[3] == p + 8)||(player1[4] == p + 8))
                        {
                            if ((player1[3] == p + 12)||(player1[4] == p + 12)||(player1[5] == p + 12))
                            {
                                if ((player1[4] == p + 16)||(player1[5] == p + 16)||(player1[6] == p + 16))
                                {
                                    f = 100+p;              
                                 }}}}}
            return (f);            
        }

        public int kare()
        {
            int i = 0, f = 0, d=0, h=0;
            for (i = 0; i < 4; i++)
            {
                if ((player1[i]%4)==0)
                {
                    if (player1[i + 1]==(player1[i]+1))
                    {
                        if (player1[i + 2] == (player1[i] + 2))
                        {
                            if (player1[i + 3] == (player1[i] + 3))
                            {
                                f = player1[i];
                                d = player1[i + 3];
                            }
                        }
                    }
                }
            }
            if (d > 0)
            {
                for (i = 0; i < 7; i++)
                {
                    if ((d != player1[i]) && ((d - 1) != player1[i]) && ((d - 2) != player1[i]) && ((d - 3) != player1[i]) && ((d - 4) != player1[i]))
                    {
                        h = player1[i];
                    }

                }
                f = f / 4 *10 + h / 4;
            }
            
        return (f);
        }

        public int ful()
        {
            int p = 90, i = 0, f = 90,j=0, e=0;
         for (i=0; i<9; i++)
         {
             e = 0;
             for (j = 6; j > 0; j--)
             {
                 if ((player1[j] >= (i * 4)) && (player1[j] < (i * 4 + 4)))
                 {
                     e = e + 1; 
                 }
             }
             if ((e == 3)&&(p==100))
             {
                 p = i;            
             }
             if ((e == 2)&&(f==100)) 
             {
                 f = i;
             } 
         }
         if ((f <90) && (p < 90))
         {
             f = 100+p*10 +f;
         }
         return (f);
       }

        public int flush()
        {    int i = 0, f = 0,j=5, m=0;
        int c = 0, v=1;
            int[] mas = new int[5];
        for (i = 6; i > 3; i--)
        {
            if (f != 4)
            {
                j = i-1;
                f = 0;
                m = player1[i] % 4;
                mas[f] = player1[i];
                while ((f != 4) && (j >= 0))
                {
                    if ((player1[j] % 4) == m)
                    {
                        f++;
                        mas[f] = player1[j];
                    }
                    j--;
                }
            }
        }
        if (f == 4)
        {
            for (i = 0; i < 5; i++)
            {
                v = 1;
                j = 4 - i;
                while (j > 0)
                {
                    v = v * 10;
                    j--;
                }
                c = c+mas[i]/4 * v;
            }
        }
            return (c);
        }
        public int stret()
        {
            int i = 0, f = 0, j = 0, e = 1, w=0;
            int[] mas = new int[5];
            for (i = 6; i > 3; i--)
            {
                for (j = (i - 1); j >= 0; j--)
                {

                    mas[0] = player1[i] / 4;
                    if (player1[i] / 4 == player1[j] / 4 + e)
                    {
                        f = f + 1;
                        mas[e] = player1[j] / 4;
                        e++;
                    }
                }
                e = 0;
                if (f == 4)
                {
                    w = mas[4];
                }
                f = 0;
            }
                 // if (((f - 1) == (player1[i] / 4)) && (j != 5))    //пропускает повторяющиеся достоинства
                //{
                 //   mas[j] = f;
                  //  j++;
               // }
               
           //     f = player1[i] / 4;         
                //   }

           // if (j == 4)
            //{
             //   e = mas[j]; 
            //}
            return (w);
        }

        public int tri()
        {
            int i = 0, f = 0, j = 0, ere = 0, w=0, d=0;
            int[] mas = new int[5];
            for (i = 0; i < 6; i++)
            {
                f = 0;
                for (j = i+1; j < 7; j++)
                {
                    if ((player1[i]/4) == (player1[j]/4))
                    {
                        f = f + 1;
                        d = player1[j];
                    }
                    if (f == 2) w = d;
                }
            }
            if (w > 0)
            {
                f = 10;
                ere = w / 4 * 100;
            }
             for (i = 6; i > 0; i--)
            {
                if (((w / 4) != (player1[i] / 4))&&(f>=1))
                {
                    ere = ere + f * (player1[i]/4);
                    f = f / 10;
                }
            }
             d = ere;
            return (d);
        }

        public int papa()
        {
            int i = 0, f = 0, w = 0, d = 0, k=0, h=0;
            int[] mas = new int[5];
            for (i = 0; i < 6; i++)
            {
                if ((player1[i]/4) == (player1[i + 1]/4))
                {
                    
                    if (d == 1)
                    {
                        f = w;
                        w = player1[i] / 4;
                        h = 1;
                    }
                    else
                    {
                        w = player1[i] / 4;
                        d = 1;
                    }
                    
                }
            }
            if (h == 1)
            {
                for (i = 6; i > 0; i--)
                {
                    if ((w != (player1[i] / 4)) && (f != (player1[i] / 4)) && (k == 0))
                    {
                        k = player1[i] / 4;

                    }
                }


            w = w * 100+f*10+k;
        }
            return (w);
        
        }

        public int para()
        {
            int i = 0, w = 0, d = 0, k = 100;
            int[] mas = new int[5];
            for (i = 0; i < 6; i++)
            {
                if ((player1[i] / 4) == (player1[i + 1] / 4))
                {
                    w = player1[i+1];
                }
               
            }
            if (w > 0)
            {
                w = w / 4;
                for (i = 6; i > 0; i--)
                {
                    if (w != (player1[i] / 4))
                    {
                        d = d + k * (player1[i] / 4);
                        k = k / 10;

                    }
                }
                d = d + w * 1000;
            }
            
            return (d);
        }

        public int kiker()
        {
            int j = 10000, w = 0, i=0;
            for (i = 6; i > 1; i--)
            {
                w = w+j * (player1[i]/4);
                j = j / 10;
            }
            return (w);
        }

            
        //    public void kombo2()
        //{
        //    for (int i = 0; i < 36; i++)
        //    {
        //        kol[i] = i;
        //    }
        //}

    }
}
